package com.heima.search.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.search.vos.SearchArticleVo;
import com.heima.search.service.SearchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-11-19 11:36
 */
@Component
public class ArticleListener {

    @Autowired
    private SearchService searchService;

    @KafkaListener(topics = ArticleConstants.ARTICLE_ES_SYNC_TOPIC)
    public void sync(String msg){


        if(StringUtils.isNotBlank(msg)){
            SearchArticleVo searchArticleVo = JSON.parseObject(msg, SearchArticleVo.class);
            searchService.syncArticleToEs(searchArticleVo);
        }
    }
}
